<!-- Connection Details -->
<h3>Connection Details</h3>
<div class="stats">
    <div><i class="fa fa-cloud"></i> Mining Pool Address: <span id="miningPoolHost"></span></div>
    
    <strong>Username</strong><br/>
    <div><i class="fa fa-key"></i> <span>Specify your wallet address</span></div>
    <div id="paymentId"><i class="fa fa-money"></i> Exchange Payment ID: <span><u>address</u><span id="paymentIdSeparator">.</span><u>paymentID</u></span></div>
    <div id="fixedDiff"><i class="fa fa-lock"></i> Difficulty locking: <span><u>address</u><span id="fixedDiffSeparator">+</span><u>diff</u></span></div>
    
    <strong>Password</strong><br/>
    <div><i class="fa fa-server"></i> Worker Identification: <span>Specify your worker name as the password</span></div>
    <div id="emailsNotification"><i class="fa fa-envelope"></i> E-mail Notifications: <span><u>workerID</u>:<u>email</u></div>
</div>

<h3>Mining Ports</h3>

<div id="miningPorts" class="table-responsive">
    <table class="table table-hover table-striped">
        <thead>
        <tr>
            <th class="col1">Port</th>
            <th class="col2">Starting Difficulty</th>
            <th class="col3">Description</th>
        </tr>
        </thead>
        <tbody id="miningPorts_rows">
        <tr>
            <td class="col1"><span class="miningPort"></span></td>
            <td class="col2"><span class="miningPortDiff"></span></td>
            <td class="col3"><span class="miningPortDesc"></span></td>
        </tr>
        </tbody>
    </table>
</div>

<!-- Configuration Generator -->
<h3>Configuration Generator</h3>

<div id="configGenerator" class="row">
    <div class="col-md-12">
        Mining Port<br/>
        <select class="form-select" id="gMiningPort"></select>
    </div>
    <div class="col-md-12">
        Wallet Address <span class="required">*</span><br/>
        <input class="form-control" id="gAddress" type="text" required="required" />
    </div>
    <div class="col-sm-9 col-xs-7">
        Exchange Payment ID<br/>
        <input class="form-control" id="gPaymentID" type="text" />
    </div>
    <div class="col-sm-3 col-xs-5">
        Static Difficulty<br/>
        <input class="form-control" id="gDifficulty" type="text" />
    </div>
    <div class="col-xs-6">
        Worker Name<br/>
        <input class="form-control" id="gWorkerName" type="text" />
    </div>
    <div class="col-xs-6">
        E-mail Address<br/>
        <input class="form-control" id="gEmail" type="email" />
    </div>
    <div class="col-md-12">
        <input id="generateConf" type="submit" value="Generate configuration" class="btn btn-default" />
    </div>
</div>

<!-- Mining Apps -->
<h3>Mining Apps</h3>
<div id="miningApps" class="table-responsive">
    <table class="table">
        <thead>
        <tr>
            <th><i class="fa fa-book"></i> App Name</th>
            <th><i class="fa fa-car"></i> Architecture</th>
            <th><i class="fa fa-download"></i> Downloads</th>
            <th><i class="fa fa-comments"></i> Discussion</th>
            <th><i class="fa fa-file-code-o"></i> Source Code</th>
        </tr>
        </thead>
        <tbody id="miningApps_rows">
        <tr class="appInfo">
            <td class="miningAppTitle">XMR Stak</td>
            <td>CPU, OpenCL (AMD), CUDA (Nvidia)</td>
            <td><a target="_blank" href="https://github.com/fireice-uk/xmr-stak/releases">Releases</a></td>
            <td><a target="_blank" href="https://github.com/fireice-uk/xmr-stak/issues">Issues</a></td>
            <td><a target="_blank" href="https://github.com/fireice-uk/xmr-stak">Github</a></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example config.txt (replace the relevant lines):</span><br/>        
                <div class="config">
                "pool_address": "<span class="exampleHost"></span>:<span class="examplePort"></span>",<br/>
                "wallet_address": "<span class="exampleLogin">YOUR_WALLET_ADDRESS</span>",<br/>
                "pool_password": "<span class="examplePassword">YOUR_WORKER_NAME"</span>,</div>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">XMRig</td>
            <td>CPU</td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig/releases">Releases</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig/issues">Issues</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig">Github</a></td>
        </tr>
        <tr class="appInfo2">
            <td class="miningAppTitle">XMRig-AMD</td>
            <td>OpenCL (AMD)</td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-amd/releases">Releases</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-amd/issues">Issues</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-amd">Github</a></td>
        </tr>
        <tr class="appInfo2">
            <td class="miningAppTitle">XMRig-NVIDIA</td>
            <td>Cuda (Nvidia)</td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-nvidia/releases">Releases</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-nvidia/issues">Issues</a></td>
            <td><a target="_blank" href="https://github.com/xmrig/xmrig-nvidia">Github</a></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example config.txt (replace the relevant lines):</span><br/>        
                <div class="config">
                "url": "<span class="exampleHost"></span>:<span class="examplePort"></span>",<br/>
                "user": "<span class="exampleLogin">YOUR_WALLET_ADDRESS</span>",<br/>
                "pass": "<span class="examplePassword">YOUR_WORKER_NAME</span>",</div>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">CPUMiner-multi</td>
            <td>CPU</td>
            <td><a target="_blank" href="https://github.com/tpruvot/cpuminer-multi/releases">Releases</a></td>
            <td><a target="_blank" href="https://github.com/tpruvot/cpuminer-multi/issues">Issues</a></td>
            <td><a target="_blank" href="https://github.com/tpruvot/cpuminer-multi">Github</a></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example:</span>
                <code>minerd -a cryptonight -o stratum+tcp://<span class="exampleHost"></span>:<span class="examplePort"></span> -u <span class="exampleLogin">YOUR_WALLET_ADDRESS</span> -p <span class="examplePassword">YOUR_WORKER_NAME</span></code>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">ccminer (forked by tsiv)</td>
            <td>CUDA (Nvidia)</td>
            <td><a target="_blank" href="https://github.com/tsiv/ccminer-cryptonight/releases">Releases</a></td>
            <td><a target="_blank" href="https://bitcointalk.org/index.php?topic=656841.msg7487737#msg7487737">BitcoinTalk</a></td>
            <td><a target="_blank" href="https://github.com/tsiv/ccminer-cryptonight">Github</a></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example:</span>
                <code>ccminer -o stratum+tcp://<span class="exampleHost"></span>:<span class="examplePort"></span> -u <span class="exampleLogin">YOUR_WALLET_ADDRESS</span> -p <span class="examplePassword">YOUR_WORKER_NAME</span></code>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">YAM Miner (by yvg1900)</td>
            <td>CPU</td>
            <td><a target="_blank" href="https://mega.co.nz/#F!UlkU0RyR!E8n4CFkqVu0WoOnsJnQkSg">MEGA</a></td>
            <td><a target="_blank" href="https://twitter.com/yvg1900">Twitter</a></td>
            <td>Proprietary <i class="fa fa-frown-o"></i></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example:</span>
                <code>yam -c x -M stratum+tcp://<span class="exampleLogin">YOUR_WALLET_ADDRESS</span>:<span class="examplePassword">YOUR_WORKER_NAME</span>@<span class="exampleHost"></span>:<span class="examplePort"></span>/xmr</code>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">Claymore CPU Miner</td>
            <td>CPU</td>
            <td><a target="_blank" href="https://bitcointalk.org/index.php?topic=647251.0">BitcoinTalk</a></td>
            <td><a target="_blank" href="https://bitcointalk.org/index.php?topic=647251.0">BitcoinTalk</a></td>
            <td>Proprietary <i class="fa fa-frown-o"></i></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example:</span>
                <code>NsCpuCNMiner64 -o stratum+tcp://<span class="exampleHost"></span>:<span class="examplePort"></span> -u <span class="exampleLogin">YOUR_WALLET_ADDRESS</span> -p <span class="examplePassword">YOUR_WORKER_NAME</span></code>
            </td>
        </tr>
        <tr class="appInfo">
            <td class="miningAppTitle">Claymore GPU Miner</td>
            <td>OpenCL (AMD)</td>
            <td><a target="_blank" href="https://bitcointalk.org/index.php?topic=638915.0">BitcoinTalk</a></td>
            <td><a target="_blank" href="https://bitcointalk.org/index.php?topic=638915.0">BitcoinTalk</a></td>
            <td>Proprietary <i class="fa fa-frown-o"></i></td>
        </tr>
        <tr class="appConfig">
            <td colspan="5">
                <span>Example:</span>
                <code>NsGpuCNMiner -o stratum+tcp://<span class="exampleHost"></span>:<span class="examplePort"></span> -u <span class="exampleLogin">YOUR_WALLET_ADDRESS</span> -p <span class="examplePassword">YOUR_WORKER_NAME</span></code>
            </td>
        </tr>
        </tbody>
    </table>
</div>

<!-- Javascript -->
<script>
currentPage = {
    destroy: function(){
    },
    update: function(){
        var portsJson = JSON.stringify(lastStats.config.ports);
        if (lastPortsJson !== portsJson) {
            lastPortsJson = portsJson;
            var $miningPortChildren = [];
	    var $miningPortOptions = [];
            for (var i = 0; i < lastStats.config.ports.length; i++) {
                var portData = lastStats.config.ports[i];
                var $portChild = $(miningPortTemplate);
                $portChild.find('.miningPort').text(portData.port);
                $portChild.find('.miningPortDiff').text(formatDifficulty(portData.difficulty));
                $portChild.find('.miningPortDesc').text(portData.desc);
                $miningPortChildren.push($portChild);
		$miningPortOptions.push('<option value="'+portData.port+'">'+portData.port+' &ndash; '+portData.desc+'</option>');
            }
            $miningPorts.empty().append($miningPortChildren);
            $miningPortSelect.empty().append($miningPortOptions);
            updateTextClasses('examplePort', lastStats.config.ports[0].port.toString());
        }

        updateTextClasses('exampleHost', poolHost);
	updateText('paymentIdSeparator', lastStats.config.paymentIdSeparator);
	updateText('fixedDiffSeparator', lastStats.config.fixedDiffSeparator);
	if (!lastStats.config.fixedDiffEnabled) $('#fixedDiff').hide();
	if (!lastStats.config.sendEmails) $('#emailsNotification').hide();
    }
};

document.getElementById('miningPoolHost').textContent = poolHost;

var lastPortsJson = '';
var $miningPorts = $('#miningPorts_rows');
var miningPortTemplate = $miningPorts.html();
$miningPorts.empty();

var $miningPortSelect = $('#gMiningPort');
$miningPortSelect.empty();

$('#generateConf').click(function() {
    // Mining Port
    var port = $('#gMiningPort').val();
    updateTextClasses('examplePort', port);

    // Username
    var address = $('#gAddress').val().replace(/\s+/g, '').trim();
    var paymentID = $('#gPaymentID').val().replace(/\s+/g, '').trim();
    var difficulty = parseInt($('#gDifficulty').val().replace(/\s+/g, '').trim());
    
    var login = address ? address : 'YOUR_WALLET_ADDRESS';
    if (paymentID) login = login + lastStats.config.paymentIdSeparator + paymentID;
    if (difficulty) login = login + lastStats.config.fixedDiffSeparator + difficulty;
    updateTextClasses('exampleLogin', login);

    // Password
    var workerName = $('#gWorkerName').val().replace(/\s+/g, '').trim();
    var email = $('#gEmail').val().replace(/\s+/g, '').trim();

    var password = workerName ? workerName : 'x';
    if (email) password = password + ':' + email;
    updateTextClasses('examplePassword', password);    
});

function formatDifficulty(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
</script>